import os
from flask_appbuilder.security.manager import (
    AUTH_OID,
    AUTH_REMOTE_USER,
    AUTH_DB,
    AUTH_LDAP,
    AUTH_OAUTH,
)

basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
    # 测试地址
    CACHE_REDIS_HOST = 'localhost'
    CACHE_REDIS_PORT = '6379'
    CACHE_REDIS_PASSWORD = 'gistide123456'
    CACHE_KEY_PREFIX = ''
    CACHE_REDIS_DB = '0'
    REDIS_URL = "redis://:{}@{}:{}/0".format(CACHE_REDIS_PASSWORD,CACHE_REDIS_HOST,CACHE_REDIS_PORT)
    # SQLALCHEMY_DATABASE_URI = 'postgresql://cloud:cloud1qaz@10.2.10.69/cloud20200820'
    SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:gistide123456@39.99.35.47:5432/jiaoyin'
    WTF_CSRF_ENABLED = False
    SECONDARY_PATH = ''
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'gistide123456'  # 之前遇到过,在启用Session的时候,一定要有它

    BASEPATH = basedir
    UPLOADPATH = os.path.join(basedir, 'upload')

    # ------------------------------
    # GLOBALS FOR APP Builder
    # ------------------------------
    # Uncomment to setup Your App name
    APP_NAME = "脚印CMS"

    # Uncomment to setup Setup an App icon
    # APP_ICON = "static/img/logo.jpg"

    # ----------------------------------------------------
    # AUTHENTICATION CONFIG
    # ----------------------------------------------------
    # The authentication type
    # AUTH_OID : Is for OpenID
    # AUTH_DB : Is for database (username/password()
    # AUTH_LDAP : Is for LDAP
    # AUTH_REMOTE_USER : Is for using REMOTE_USER from web server
    AUTH_TYPE = AUTH_DB

    # Uncomment to setup Full admin role name
    # AUTH_ROLE_ADMIN = 'Admin'

    # Uncomment to setup Public role name, no authentication needed
    # AUTH_ROLE_PUBLIC = 'Public'

    # Will allow user self registration
    # AUTH_USER_REGISTRATION = True

    # The default user self registration role
    # AUTH_USER_REGISTRATION_ROLE = "Public"

    # When using LDAP Auth, setup the ldap server
    # AUTH_LDAP_SERVER = "ldap://ldapserver.new"

    # Uncomment to setup OpenID providers example for OpenID authentication
    # OPENID_PROVIDERS = [
    #    { 'name': 'Yahoo', 'url': 'https://me.yahoo.com' },
    #    { 'name': 'AOL', 'url': 'http://openid.aol.com/<username>' },
    #    { 'name': 'Flickr', 'url': 'http://www.flickr.com/<username>' },
    #    { 'name': 'MyOpenID', 'url': 'https://www.myopenid.com' }]
    # ---------------------------------------------------
    # Babel config for translations
    # ---------------------------------------------------
    # Setup default language
    BABEL_DEFAULT_LOCALE = "zh"
    # Your application default translation path
    BABEL_DEFAULT_FOLDER = "translations"
    # The allowed translation for you app
    LANGUAGES = {
        "en": {"flag": "gb", "name": "English"},
        "pt": {"flag": "pt", "name": "Portuguese"},
        "pt_BR": {"flag": "br", "name": "Pt Brazil"},
        "es": {"flag": "es", "name": "Spanish"},
        "de": {"flag": "de", "name": "German"},
        "zh": {"flag": "cn", "name": "Chinese"},
        "ru": {"flag": "ru", "name": "Russian"},
        "pl": {"flag": "pl", "name": "Polish"},
    }
    # ---------------------------------------------------
    # Image and file configuration
    # ---------------------------------------------------
    # The file upload folder, when using models with files
    UPLOAD_FOLDER = basedir + "/app/static/uploads/"

    # The image upload folder, when using models with images
    IMG_UPLOAD_FOLDER = basedir + "/app/static/uploads/"

    # The image upload url, when using models with images
    IMG_UPLOAD_URL = "/static/uploads/"
    # Setup image size default is (300, 200, True)
    # IMG_SIZE = (300, 200, True)

    # Theme configuration
    # these are located on static/appbuilder/css/themes
    # you can create your own and easily use them placing them on the same dir structure to override
    # APP_THEME = "bootstrap-theme.css"  # default bootstrap
    # APP_THEME = "cerulean.css"
    # APP_THEME = "amelia.css"
    # APP_THEME = "cosmo.css"
    # APP_THEME = "cyborg.css"
    # APP_THEME = "flatly.css"
    # APP_THEME = "journal.css"
    # APP_THEME = "readable.css"
    # APP_THEME = "simplex.css"
    # APP_THEME = "slate.css"
    # APP_THEME = "spacelab.css"
    # APP_THEME = "united.css"
    # APP_THEME = "yeti.css"
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    ITEMS_PER_PAGE = 10
    JWT_AUTH_URL_RULE = '/api/auth'

    @staticmethod
    def init_app(app):
        pass



class DevelopmentConfig(Config):
    DEBUG = True

    @classmethod
    def init_app(cls, app):
        Config.init_app(app)


class TestingConfig(Config):
    TESTING = True

    @classmethod
    def init_app(cls, app):
        Config.init_app(app)


class ProductionConfig(Config):
    PRODUCTION = True

    @classmethod
    def init_app(cls, app):
        Config.init_app(app)


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}

